﻿using System;
using System.Text;
using System.Web.UI.WebControls;
using Lswweb.Domain;
using Lswweb.Model;

namespace Lswweb.Controls
{
    public class SinglePageShow : SkinnedWebControl
    {
        private SinglePage type = (SinglePage)SiteContext.Current.Id;
        private Label lbTitle;
        private Image image;
        private Label lbBody;
  
        public SinglePage PageType
        {
            get { return type; }
            set { type = value; }
        }


        protected override void InitializeSkin(System.Web.UI.Control skin)
        {
            lbTitle = (Label)skin.FindControl("lbTitle");
            image = (Image)skin.FindControl("image");
            lbBody = (Label)skin.FindControl("lbBody");

            if (!Enum.IsDefined(typeof(SinglePage), PageType))
            {
                throw new SiteException(ExceptionType.PageNotFond);
            }
            else
            {
                if (lbTitle != null)
                    lbTitle.Text = SinglePage.Title;

                if (lbBody != null)
                    lbBody.Text = SinglePage.View;

                if (image != null)
                    image.ImageUrl = SinglePage.ImageUrl;
            }

        }

        private SinglePageInfo _page;
        public SinglePageInfo SinglePage
        {
            get
            {
                if (_page == null)
                {
                    _page = SinglePages.GetSinglePage(PageType);
                    if (_page == null)
                        _page = new SinglePageInfo(PageType);
                }

                return _page;
            }
        }

        protected override string DefaultSkinFilename
        {
            get { return string.Empty; }
        }
    }
}
